﻿using SharpDepend.Datatypes;
using ZquenceStudio3Host.Graphics.Components;
using ZquenceStudio3Host.Graphics.GUI;

namespace DefaultDspPlugins.UI.Common.Modulizer.Engine.GUIv2.FrontEndComponents
{
    public class ZoomablePanel : Panel
    {
        private Panel mContent;

        public Panel Content
        {
            get { return mContent; }
            set
            {
                if (mContent != value)
                {
                    if (mContent != null)
                    {
                        RemoveComponent(mContent);
                    }

                    mContent = value;

                    if (value != null)
                    {
                        AddComponent(value);
                        Events_OnScaleChanged();
                    }
                }
            }
        }

        public ZoomablePanel(BasicGuiManager engineCore) : base(engineCore)
        {
            BackgroundColor = Color.Black;
            Events.OnScaleChanged += Events_OnScaleChanged;
        }

        private void Events_OnScaleChanged()
        {
            mContent.DimensionInProcent = false;
            double smalestSize = RealWidth > RealHeight ? RealHeight : RealWidth;

            mContent.X = RealWidth * 0.5 - smalestSize * 0.5;
            mContent.Y = RealHeight * 0.5 - smalestSize * 0.5;
            mContent.Width = smalestSize;
            mContent.Height = smalestSize;
        }

        public override bool OnMouseDown(double x, double y, int id)
        {
            return false;
        }
    }
}
